﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Validation;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NCT.INVPOS.DataAccessLayer.Configurations;
using NCT.INVPOS.DataAccessLayer.Context;
using NCT.INVPOS.DataAccessLayer.Entity;

namespace NCT.INVPOS.DataAccessLayer
{
    public class AppContext : DbContext, IDbContext, IAppContext, IDisposable
    {
        
        public AppContext()
            :base("pos_inv")
        {
                
        }

        public DbSet<Product> Products { get; set; }
        public DbSet<Customer> Customers { get; set; }
        public DbSet<Branch> Branches { get; set; }
        public DbSet<Category> Categories { get; set; }
        public DbSet<Manufacturer> Manufacturers { get; set; }
        public DbSet<Supplier> Suppliers { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add<Product>(new ProductConfiguration());
            modelBuilder.Configurations.Add<Customer>(new  CustomerConfiguration());
            modelBuilder.Configurations.Add<Branch>(new BranchConfiguration());
            modelBuilder.Configurations.Add<Category>(new CategoryConfiguration());
            modelBuilder.Configurations.Add<Manufacturer>(new ManufacturerConfiguration());
            modelBuilder.Configurations.Add<Supplier>(new SupplierConfiguration());

            base.OnModelCreating(modelBuilder);
        }

        public override int SaveChanges()
        {
            return base.SaveChanges();
        }
        public new IDbSet<TEntity> Set<TEntity>() where TEntity : class
        {
            return base.Set<TEntity>();
        }

        public IEnumerable<DbEntityValidationResult> GetValidationResult()
        {
            return GetValidationErrors();
        }
    }

}
